#!/usr/bin/python

"""test2.py

this script is
"""

__author__ = 'takahiro'
__version__ = '2014-02-10 1.00 (takahiro)'

import sys
import optparse

usage = "%prog [filename] <TA5_NUM> <TA25_NUM> <TA5_UPDOWN UP:1, DOWN:0> <TA25_UPDOWN>"
parser = optparse.OptionParser( usage=usage )
parser.parse_args( )

UP = 1
DOWN = 0

SIGNAL_ON = 1
SIGNAL_OFF = 0

if len( sys.argv ) == 5:
  stream = sys.stdin
  arg_index = 1
elif len( sys.argv ) == 6:
  stream = open( sys.argv[ 1 ], 'r' )
  arg_index = 2
else:
  parser.print_help( )
  exit( )

TA5_NUM = int(sys.argv[arg_index+0])
TA25_NUM = int(sys.argv[arg_index+1])
TA5_UPDOWN = int(sys.argv[arg_index+2])
TA25_UPDOWN = int(sys.argv[arg_index+3])

def valid_args():
  if TA5_NUM < 0:
    return False
  if TA25_NUM < 0:
    return False
  if TA5_UPDOWN != UP and TA5_UPDOWN != DOWN:
    return False
  if TA25_UPDOWN != UP and TA25_UPDOWN != DOWN:
    return False
  return True

if not valid_args():
  parser.print_help()
  exit()

keys = open('format.arg', 'r').readlines()[0].rstrip().split(' ')

datas = []

for line in stream:
  datas.append(line.rstrip().split('\t'))

def judge_trend(datas, i, num, key, ud):
  flag = SIGNAL_ON
  for n in range(0, num):
    t = int(datas[i-n][keys.index(key)])
    if ud == DOWN and t >= 0:
      flag = SIGNAL_OFF
    elif ud == UP and t <= 0:
      flag = SIGNAL_OFF
  return flag

def judge_today_reverse_trend(v, key, ud):
  t = int(v[keys.index(key)])
  flag = SIGNAL_ON
  if ud == UP and t >= 0:
    flag = SIGNAL_OFF
  elif ud == DOWN and t <= 0:
    flag = SIGNAL_OFF
  return flag

for i, v in enumerate(datas):
  if i < TA5_NUM+1 or i < TA25_NUM:
    print SIGNAL_OFF
    continue

  ra5_flag = judge_today_reverse_trend(v, 'ta5', TA5_UPDOWN) 
  ta5_flag = judge_trend(datas, i-1, TA5_NUM, 'ta5', TA5_UPDOWN)
  ta25_flag = judge_trend(datas, i, TA25_NUM, 'ta25', TA25_UPDOWN)
  if ra5_flag == SIGNAL_ON and ta5_flag == SIGNAL_ON and ta25_flag == SIGNAL_ON:
    flag = SIGNAL_ON
  else:
    flag = SIGNAL_OFF
  print flag

